<!DOCTYPE HTML>
<html lang="en">
<head>
<title>#InstallKeybdHook - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The #InstallKeybdHook directive forces the unconditional installation of the keyboard hook." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>#InstallKeybdHook</h1>

<p>Forces the unconditional installation of the keyboard hook.</p>

<pre class="Syntax"><span class="func">#InstallKeybdHook</span></pre>
<h2>Remarks</h2>
<p>The keyboard hook monitors keystrokes for the purpose of activating <a href="../Hotstrings.htm">hotstrings</a> and any keyboard <a href="../Hotkeys.htm">hotkeys</a> not supported by RegisterHotkey (which is a function built into the operating system). It also supports a few other features such as the <a href="Input.htm">Input</a> command.</p>
<p>AutoHotkey does not install the keyboard and mouse hooks unconditionally because together they consume at least 500 KB of memory. Therefore, the keyboard hook is normally installed only when the script contains one of the following: 1) <a href="../Hotstrings.htm">hotstrings</a>; 2) one or more <a href="../Hotkeys.htm">hotkeys</a> that require the keyboard hook (most do not); 3) <a href="SetNumScrollCapsLockState.htm">SetCaps/Scroll/NumLock AlwaysOn/AlwaysOff</a>; 4) the <a href="Input.htm">Input</a> command, for which the hook is installed upon first actual use.</p>
<p>By contrast, the #InstallKeybdHook directive will unconditionally install the keyboard hook, which might be useful to allow <a href="KeyHistory.htm">KeyHistory</a> to display the last 20 keystrokes (for debugging purposes), or to avoid the need for <a href="_HotkeyModifierTimeout.htm">#HotkeyModifierTimeout</a>.</p>
<p>You can determine whether a script is using the hook via the <a href="KeyHistory.htm">KeyHistory</a> command or menu item. You can determine which hotkeys are using the hook via the <a href="ListHotkeys.htm">ListHotkeys</a> command or menu item.</p>
<p>This directive also makes a script <a href="_Persistent.htm">persistent</a>, meaning that <a href="ExitApp.htm">ExitApp</a> should be used to terminate it.</p>
<h2>Related</h2>
<p><a href="_InstallMouseHook.htm">#InstallMouseHook</a>, <a href="_UseHook.htm">#UseHook</a>, <a href="Hotkey.htm">Hotkey</a>, <a href="Input.htm">Input</a>, <a href="_Persistent.htm">#Persistent</a>, <a href="KeyHistory.htm">KeyHistory</a>, <a href="../Hotstrings.htm">Hotstrings</a>, <a href="GetKeyState.htm">GetKeyState</a>, <a href="KeyWait.htm">KeyWait</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>#InstallKeybdHook</pre>
</div>

</body>
</html>
